home *** CD-ROM | disk | FTP | other *** search
/ Top 200 Programs / Top 200 Programs.iso / Bob8 / THOMPSON / LIBERTY / PRODUCT / TUTORIAL.EXE / CALLER.BAS < prev    next >
BASIC Source File  |  1996-02-27  |  6KB  |  223 lines

  1.  
  2.     'CALLER.LOG
  3.     'Here is the solution to our homework assignment for
  4.     'week 3 of our Liberty BASIC course
  5.     'Copyright 1996 Shoptalk Systems
  6.     'All rights reserved
  7.  
  8. [menu]  'display menu options
  9.  
  10.     cls
  11.     print "**Caller Log Program**"
  12.     print
  13.     print " 1) Enter a phone call"
  14.     print " 2) Search by caller's name"
  15.     print " 3) Search by person called"
  16.     print " 4) Quit"
  17.     print
  18.     print "Choose an option from 1 to 4."
  19.     input ">"; option
  20.  
  21.     if option < 1 or option > 4 then gosub [badOption]
  22.     if option = 1 then gosub [enterAPhoneCall]
  23.     if option = 2 then gosub [searchByCallersName]
  24.     if option = 3 then gosub [searchByPersonCalled]
  25.     if option = 4 then [quit]
  26.  
  27.     goto [menu]
  28.  
  29. [badOption]  'display a notice that a bad selection was made
  30.  
  31.     print
  32.     beep
  33.     print "Option "; option; " is unsupported."
  34.     print "Press any key."
  35.     dummyVar$ = input$(1)
  36.  
  37.     return
  38.  
  39. [enterAPhoneCall]  'accept a phone log entry from the user
  40.  
  41.     cls
  42.     print "**Enter a Phone Call**"
  43.     print
  44.  
  45.     input "Caller's name ?"; callersName$
  46.     input "Name of person called ?"; personCalled$
  47.     input "Date of call (press 'Enter' for "+date$()+") ?"; dateOfCall$
  48.     if dateOfCall$ = "" then dateOfCall$ = date$()
  49.     input "Time of call (press 'Enter' for "+time$()+") ?"; timeOfCall$
  50.     if timeOfCall$ = "" then timeOfCall$ = time$()
  51.     input "Purpose of call ?"; purposeOfCall$
  52.     input "Phone # where the caller can be reached ?"; callersPhone$
  53.  
  54.  
  55. [saveEditCancelLoop]  'give the user the option to save, edit or abort
  56.  
  57.     cls
  58.     gosub [displayEntryInfo]
  59.     print "Save, Edit, Cancel Entry (S/E/C)?";
  60.     answer$ = input$(1)
  61.  
  62.     if answer$ = "S" or answer$ = "s" then gosub [saveEntry] : goto [menu]
  63.     if answer$ = "E" or answer$ = "e" then gosub [editEntry]
  64.     if answer$ = "C" or answer$ = "c" then [menu]
  65.  
  66.     goto [saveEditCancelLoop]
  67.  
  68.  
  69. [displayEntryInfo]  'display call information
  70.  
  71.     print "           Caller's name : "; callersName$
  72.     print "   Name of person called : "; personCalled$
  73.     print "            Date of call : "; dateOfCall$
  74.     print "            Time of call : "; timeOfCall$
  75.     print "         Purpose of call : "; purposeOfCall$
  76.     print "Caller can be reached at : "; callersPhone$
  77.  
  78.     return
  79.  
  80.  
  81. [editEntry]  'edit call information
  82.  
  83.     cls
  84.     print "**Edit Caller Entry**"
  85.     print
  86.  
  87.     print "           Caller's name : "; callersName$
  88.     input "  Press Enter, or retype > "; newEntry$
  89.     if newEntry$ <> "" then callersName$ = newEntry$
  90.  
  91.     print "   Name of person called : "; personCalled$
  92.     input "  Press Enter, or retype > "; newEntry$
  93.     if newEntry$ <> "" then personCalled$ = newEntry$
  94.  
  95.     print "            Date of call : "; dateOfCall$
  96.     input "  Press Enter, or retype > "; newEntry$
  97.     if newEntry$ <> "" then dateOfCall$ = newEntry$
  98.  
  99.     print "            Time of call : "; timeOfCall$
  100.     input "  Press Enter, or retype > "; newEntry$
  101.     if newEntry$ <> "" then timeOfCall$ = newEntry$
  102.  
  103.     print "         Purpose of call : "; purposeOfCall$
  104.     input "  Press Enter, or retype > "; newEntry$
  105.     if newEntry$ <> "" then purposeOfCall$ = newEntry$
  106.  
  107.     print "Caller can be reached at : "; callersPhone$
  108.     input "  Press Enter, or retype > "; newEntry$
  109.     if newEntry$ <> "" then callersPhone$ = newEntry$
  110.  
  111.     return
  112.  
  113.  
  114. [saveEntry]  'write the entry info to PHONELOG.TXT
  115.  
  116.     open "PHONELOG.TXT" for append as #out
  117.  
  118.     print #out, callersName$
  119.     print #out, personCalled$
  120.     print #out, dateOfCall$
  121.     print #out, timeOfCall$
  122.     print #out, purposeOfCall$
  123.     print #out, callersPhone$
  124.  
  125.     close #out
  126.  
  127.     return
  128.  
  129.  
  130. [searchByCallersName]  'look for a phone log entry by caller's name
  131.  
  132.     cls
  133.     print "**Search by Caller's Name**"
  134.     print
  135.     print "Please enter a partial name to search by."
  136.     input ">"; searchCaller$
  137.     if searchCaller$ = "" then [menu]  'nothing entered, abort search
  138.  
  139.     searchCaller$ = upper$(searchCaller$) 'convert to uppercase for search
  140.  
  141.     open "PHONELOG.TXT" for input as #in
  142.  
  143.     foundFlag = 0
  144.     quitFlag = 0
  145.     if eof(#in) = -1 then [endOfCallerSearch]
  146.  
  147.  
  148. [searchByCallerLoop]
  149.     gosub [readEntry]  'get next entry from PHONELOG.TXT
  150.     if instr(upper$(callersName$), searchCaller$) > 0 then gosub [matched]
  151.     if eof(#in) = 0 and quitFlag = 0 then [searchByCallerLoop]
  152.  
  153.  
  154. [endOfCallerSearch]
  155.     close #in
  156.     if foundFlag = 0 then print "No matches."
  157.     print "Press any key."
  158.     dummyVar$ = input$(1)
  159.     goto [menu]
  160.  
  161.  
  162. [searchByPersonCalled]  'look for a phone log entry by person called
  163.  
  164.     cls
  165.     print "**Search by Person Called**"
  166.     print
  167.     print "Please enter a partial name to search by."
  168.     input ">"; searchCalled$
  169.     if searchCalled$ = "" then [menu]  'nothing entered, abort search
  170.  
  171.     searchCalled$ = upper$(searchCalled$) 'convert to uppercase for search
  172.  
  173.     open "PHONELOG.TXT" for input as #in
  174.  
  175.     foundFlag = 0
  176.     quitFlag = 0
  177.     if eof(#in) = -1 then [endOfCalledSearch]
  178.  
  179.  
  180. [searchByCalledLoop]
  181.     gosub [readEntry]  'get next entry from PHONELOG.TXT
  182.     if instr(upper$(personCalled$), searchCalled$) > 0 then gosub [matched]
  183.     if eof(#in) = 0 and quitFlag = 0 then [searchByCalledLoop]
  184.  
  185.  
  186. [endOfCalledSearch]
  187.     close #in
  188.     if foundFlag = 0 then print "No matches."
  189.     print "Press any key."
  190.     dummyVar$ = input$(1)
  191.     goto [menu]
  192.  
  193.  
  194. [readEntry]  'read the next entry from PHONELOG.TXT
  195.  
  196.     line input #in, callersName$
  197.     line input #in, personCalled$
  198.     line input #in, dateOfCall$
  199.     line input #in, timeOfCall$
  200.     line input #in, purposeOfCall$
  201.     line input #in, callersPhone$
  202.  
  203.     return
  204.  
  205.  
  206. [matched]  'stop and show a match & ask what to do next
  207.  
  208.     foundFlag = 1
  209.     print "---------Match---------"
  210.     gosub [displayEntryInfo]
  211.     print
  212.     print "Next Entry, Quit Searching (N/Q)?"
  213.     answer$ = input$(1)
  214.     'only check for quit response
  215.     if answer$ = "Q" or answer$ = "q" then quitFlag = 1
  216.  
  217.     return
  218.  
  219.  
  220. [quit]  'end CALLER.BAS here
  221.  
  222.     end
  223.